const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken')
const userList = [{
	username: '张三',
	password: "123"
},
{
	username: '李四',
	password: "123456"
}]

module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())

			app.post('/api/login', (req, res) => {
				const { username, password } = req.body
				
				const isLogin = userList.some(item => item.username === username && item.password === password)

				if(isLogin) {
					res.send({
						code: 200,
						token: jwt.sign(username, '666666')
					})
				} else {
					res.send({
						code: 404,
					})
				}

			})
		}
	}
}